<template>
  <div class="login">
    <!-- <el-button type="primary" @click="login">登陆设置Token</el-button> -->
    <div class="mask">
      <div class="left">
        <span class="msg">
          NURSE PLUS EDUCATION BACKGROUND<br />MANAGEMENT SYSTEM
        </span>
        <span>护士加教育业务后台管理系统</span>
      </div>
      <div class="right">
        <div class="title">
          <span class="title_type">账号登录</span>
        </div>
        <div class="form">
          <div class="ins">
            <p>手机号</p>
            <el-input
              class="input"
              placeholder="请输入"
              v-model.trim="loginParams.userAdminTel"
              maxlength="11"
            />
          </div>
          <div class="ins">
            <p>密码</p>
            <div class="eye">
              <el-input
                class="input password"
                placeholder="请输入"
                v-model.trim="loginParams.password"
                :type="eye ? 'password' : ''"
                @keyup.enter="login"
              />
              <img
                :src="
                  eye
                    ? require('./img/yanjing.png')
                    : require('./img/yanjing2.png')
                "
                @click="eye = !eye"
                class="eye-icon"
                alt=""
              />
            </div>
          </div>
          <el-button
            type="primary"
            class="login-btn"
            :loading="loginLoading"
            style=""
            @click.native="accountLogin"
            >登录
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";
import Config from "@/config/app.js";
import { login as loginApi } from "@/api/user/user.js";
export default {
  data() {
    return {
      count: 60,
      timer: null,
      eye: true,
      isPassword: true,
      loginLoading: false,
      loginParams: {
        password: "",
        userAdminTel: ""
      }
    };
  },
  methods: {
    ...mapActions("d2admin/account", ["login", "logout"]),
    accountLogin() {
      const RegPhone = /^1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/;
      if (!this.loginParams.userAdminTel) {
        this.$notify({
          title: "请输入手机号",
          type: "warning"
        });
        return;
      }
      if (!RegPhone.test(this.loginParams.userAdminTel)) {
        this.$notify({
          title: "请输入正确的手机号",
          type: "warning"
        });
        return;
      }
      if (!this.loginParams.password) {
        this.$notify({
          title: "请输入密码",
          type: "warning"
        });
        return;
      }
      this.loginLoading = true;
      loginApi({
        mobile: this.loginParams.userAdminTel,
        password: this.loginParams.password,
        platform: Config.platformUUID
      })
        .then(async res => {
          this.$notify({
            title: "登录成功",
            type: "success"
          });
          await this.login(res);
          this.$router.replace(this.$route.query.redirect || "/dashboard");
        })
        .catch(e => {
          this.$message(JSON.stringify(e));
          this.loginLoading = false;
        });
    }
  },
  created() {
    this.logout();
  }
};
</script>
<style lang="scss">
.login {
  width: 100%;
  height: 100%;
  background: url("./img/bg_img.png") no-repeat;
  background-size: 100% 100%;
  position: relative;
  min-width: 1366px;
  .mask {
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    // width: 1200px;
    width: 966px;
    margin: 0 auto;
  }
  .left {
    display: flex;
    flex-direction: column;
    color: #fffcda;
    font-size: 40px;
    font-family: Source Han Serif CN;
    font-weight: bold;
    line-height: 26px;
    .msg {
      font-size: 24px;
      line-height: 40px;
      margin-bottom: 40px;
      font-style: italic;
    }
    .left-title {
      font-family: "Helvetica Neue", Helvetica, "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
    }
  }
  .right {
    width: 320px;
    height: 430px;
    background: #fff;
    border-radius: 8px;
    padding: 50px 20px;
    box-sizing: border-box;
    .title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 35px;
      p {
        font-size: 14px;
        color: #848490;
        cursor: pointer;
        display: flex;
        align-items: center;
        img {
          display: inline-block;
          margin-left: 3px;
        }
      }
      .title_type {
        font-size: 20px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: rgba(35, 137, 255, 1);
        line-height: 30px;
      }
    }
    .ins {
      display: flex;
      width: 100%;
      border-bottom: 1px solid rgba(234, 234, 234, 1);
      align-items: center;
      margin-top: 20px;
      p {
        font-size: 14px;
        color: #333;
        margin-right: 10px;
        width: 42px;
        text-align-last: justify;
        vertical-align: top;
      }
      span {
        font-size: 14px;
        color: rgba(35, 137, 255, 1);
        position: relative;
        cursor: pointer;
        &::before {
          content: "";
          width: 1px;
          height: 16px;
          background: rgba(234, 234, 234, 1);
          position: absolute;
          left: -6px;
          top: 50%;
          margin-top: -8px;
          cursor: pointer;
        }
      }
      .input {
        flex: 1;
        height: 100%;
      }
      .el-input__inner {
        border: none;
        outline: none;
        font-size: 18px;
        color: #333;
      }
      .eye {
        display: flex;
        align-items: center;
        cursor: pointer;
        .eye-icon {
          width: 20px;
          // height: 12px;
        }
      }
    }
    .forget_password {
      margin-top: 13px;
      text-align: right;
      font-size: 14px;
      color: rgba(132, 132, 144, 1);
      cursor: pointer;
    }
    .remind {
      text-align: center;
      color: #848490;
      font-size: 14px;
      margin-top: 17px;
      span {
        color: #2389ff;
        cursor: pointer;
      }
    }
  }
}
.login-btn {
  width: 100%;
  margin-top: 115px;
  height: 44px;
}
</style>
